package de.koller.oceanFramework.plain.fullParticle;

import de.koller.oceanFramework.OceanException;
import de.koller.oceanFramework.tree.Sea3X;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferInt;

/**
 * 
 * @author Fabian Koller
 */
public class ParticleImage extends Sea3X {
	private PondGraphics pgraphics;
	private Graphics2D graphics;
	private BufferedImage bitmap;
	private final int bitmapWidth, bitmapHeight;
	@Deprecated
	private final float scale;
	private boolean transparent = false;

	/**
	 * 
	 * @param bitmapWidth
	 * @param bitmapHeight
	 * @param scale
	 */
	@Deprecated
	public ParticleImage( int bitmapWidth, int bitmapHeight, float scale ) {
		this.bitmapWidth = bitmapWidth;
		this.bitmapHeight = bitmapHeight;
		this.scale = scale;
	}

	public ParticleImage( int bitmapWidth, int bitmapHeight ) {
		this( bitmapWidth, bitmapHeight, 1 );
	}
	/**
	 * 
	 */
	@Override
	protected void init() {
		super.init();
		
		nMethod();
	}

	@Override
	protected void release() {
		super.release();
		
		graphics.dispose();
	}

	public void setTransparent( boolean transparent ) {
		if( isInitialized() )
			throw new OceanException( "already initialized!" );
		this.transparent = transparent;
	}
	
	
	
	private void nMethod() {
		bitmap = new BufferedImage( bitmapWidth, bitmapHeight, 
				transparent ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB );
		pgraphics = new PondGraphics( ((DataBufferInt)bitmap.getRaster().getDataBuffer()).getData() );
		graphics = bitmap.createGraphics();
		this.addChild( pgraphics );
	}

	/**
	 * 
	 * @return
	 */
	public Image getBitmap() {
		return bitmap;
	}

	/**
	 * 
	 * @return
	 */
	public int getBitmapHeight() {
		return bitmapHeight;
	}

	/**
	 * 
	 * @return
	 */
	public int getBitmapWidth() {
		return bitmapWidth;
	}

	/**
	 * 
	 * @return
	 */
	public PondGraphics getPgraphics() {
		return pgraphics;
	}

	/**
	 * 
	 * @return
	 */
	@Deprecated
	public float getScale() {
		return scale;
	}

	/**
	 * 
	 * @return
	 */
	public int[] getPixels() {
		return pgraphics.getPixels();
	}

	public Graphics2D getGraphics() {
		return graphics;
	}
	
}
